#include <math.h>
#include "vec3.h"
#include "Value.h"

#define EPSILON 0.01f

#pragma warning(disable : 4312)

bool value::operator==(value &rhs)
{
	value kind((void *)0xDEADBEEF);

	if (type == rhs.type)
		kind = type;

	if (kind.p_value == (void *)0xDEADBEEF)
		return false; // WRONG TYPEZ
		
	switch(kind.type)
	{
	case tBOOLEAN:
		if (b_value == rhs.b_value) return true;
		return false;
		break;
	case tINTEGER:
		if (u_value == rhs.u_value) return true;
		return false;
		break;
	case tFLOATING:
		if (fabs(f_value - rhs.f_value) < EPSILON) return true;
		return false;
		break;
	case tVECTOR3:
		if (fabs(vec3f(vec3f(v_value[0], v_value[1], v_value[2]) - vec3f(rhs.v_value[0], rhs.v_value[1], rhs.v_value[2])).magnitude()) < EPSILON) return true;
		return false;
		break;
	case tPOINTER:
		if (p_value == rhs.p_value) return true; // check if objects have same memory address...
		return false;
		break;
	default:
		return false;
		break;
	};
	return false;
}
